package com.asdc.demo.exchage;

import com.asdc.demo.utils.RabbitMqUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;

/**
 * @ClassName ReceiveLogs01
 * @Author bsy
 * @Description 交换机
 *
 * @Date 2022/3/13 20:34
 * @Version 1.0
 */
public class ReceiveLogs02 {
    private static final String EXCHANE_NAME = "logs";
    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();
        //交换机类型
        channel.exchangeDeclare(EXCHANE_NAME,"fanout");
        //生成临时队列
        String queue = channel.queueDeclare().getQueue();
        //绑定
        channel.queueBind(queue,EXCHANE_NAME,"");
        DeliverCallback deliverCallback = (consumerTag, delivery) ->
        {String message = new String(delivery.getBody(), "UTF-8");
            System.out.println("ReceiveLogs02 控制台打印接收到的消息"+message);
        };

        channel.basicConsume(queue, true, deliverCallback, consumerTag -> { });
    }
}
